var exec = require('cordova/exec');
 
var SpeakNative=function(){};
SpeakNative.prototype.init=function(parms,success,error){
	 if(!parms)parms={};
	 exec(success,error, "SpeakNative", "init", [parms]);
};
SpeakNative.prototype.speak=function(utterance){
	var successCallback = function(event) {
		if (event.type === "end" && typeof utterance.onend === "function") {
			utterance.onend(event);
		}
	};
	var errorCallback = function() {
		if (typeof utterance.onerror === "function") {
			utterance.onerror();
		}
	};
	exec(successCallback, errorCallback, "SpeakNative", "speak", [utterance]);
};
SpeakNative.prototype.cancel=function(success, error){
	exec(null,null, "SpeakNative", "cancel", []);
};
var parms={};
SpeakNative.prototype.silence=function(b) {
	if(b==null){
		parms.silence=true;
	}else{
		parms.silence=b;
	}
	var success=function(systemVolume){
		if(systemVolume==0){
			parms.systemVolume=parms.systemVolume;
		}else{
			parms.systemVolume=systemVolume
		}
		exec(null, null, "SpeakNative", "silence",[parms]);
	};
	exec(success, null, "SpeakNative", "getSystemVolume", [parms]);
};
SpeakNative.prototype.setSystemVolume=function(volume) {
	exec(null, null, "SpeakNative", "setSystemVolume", [volume]);
};
 
module.exports = new SpeakNative();
